package com.anolesoft.amljmes.delivery.controller;

import java.util.List;

import com.anolesoft.amljmes.delivery.dto.MesTqqszDto;
import com.anolesoft.amljmes.foreknow.mapper.STFEmployeeMapper;
import com.anolesoft.common.core.domain.LoginUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.anolesoft.amljmes.delivery.dto.MesZcjhDto;
import com.anolesoft.amljmes.delivery.service.MesZcjhService;
import com.anolesoft.common.core.web.domain.AjaxResult;
import com.anolesoft.yr.demo.PageResult;
import com.anolesoft.yr.util.Constants;
import com.anolesoft.yr.util.HttpStatus;

import javax.annotation.Resource;

/**
 * 
 * @author 王佳明
 * @date 2022/5/11
 *
 */
@RestController
@CrossOrigin
@RequestMapping(value = "/zcjh")
public class MesZcjhController {

	@Autowired
	MesZcjhService service;
	@Resource
	private STFEmployeeMapper name;

	@RequestMapping(value = "/querylist",method = RequestMethod.POST)
	public AjaxResult querylist(@RequestBody MesZcjhDto dto ) {
		// 新加限制厂代号_sjm
		LoginUser loginUser = com.anolesoft.yr.util.SecurityUtils.getLoginUser();
		String fcode = loginUser.getFacCode();
		dto.setChangdaihao(fcode);
		if (dto.getDingdanbianhao() != null) {
			dto.setDingdanbianhao(dto.getDingdanbianhao().trim());
		}
		if (dto.getKehu() != null) {
			dto.setKehu(dto.getKehu().trim());
		}
		List<MesZcjhDto> allList=service.queryList(dto);
		// 新加页面显示修改人姓名_sjm
//		for (MesZcjhDto c:
//				allList) {
//			c.setXiadaren(name.getname(c.getXiadaren()));
//		}
		Integer endIndex = dto.getPageNumber()  * dto.getPageSize() > allList.size() ? allList.size() : dto.getPageNumber()  * dto.getPageSize();
		
		List<MesZcjhDto> list = allList.subList( (dto.getPageNumber() -1) *dto.getPageSize(), endIndex);
		
		PageResult pageResult = new PageResult(list, dto.getPageSize(), dto.getPageNumber(), allList.size());
		
		return new AjaxResult(HttpStatus.SUCCESS, Constants.QUERY_SUCCESS_MESSAGE,pageResult);
		
	}
	
}
